<?php
/**
 * 计算点击数
 */
$type = $argv[1];
$dataFile = dirname(__FILE__) . "/data/{$type}.data";
$typeArr = array("document");
if(!in_array($type,$typeArr)){
    echo "类型错误!";
    exit;
}
$handle = @fopen($dataFile, "r");
if ($handle) {
    while (!feof($handle)) {
        $buffer = trim(fgets($handle));
        $buffer = preg_replace('/\s{2,}/', ' ', $buffer); //去掉多余的空格
        switch ($type){
            case "document":
                $tmpArr = explode(' ', $buffer);var_dump($tmpArr);
                if(is_array($tmpArr) && count($tmpArr) == 3){
                    $cnt   = (int)trim($tmpArr[0]);
                    $docId = (int)trim($tmpArr[1]);
                    $appId = (int)trim($tmpArr[2]);
                    if($cnt && $docId && $appId){
                        $sql = "UPDATE cms_document_title_{$appId} SET hits = hits + {$cnt} WHERE id = {$docId}";
                        
                        //echo $sql;
                    }
                }
                break;
        }
    }
    fclose($handle);
}


?>